﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;

namespace AssignmentSolutions
{
    class Program
    {
        static void Main(string[] args)
        {
            Assignment1();
            Assignment2();
            Assignment3();
            Console.ReadLine();
        }
        /// <summary>
        /// Resenje Zadatka1
        /// Thread i Lambda Expression
        /// </summary>
        public static void Assignment1()
        {
            Thread t1 = new Thread(() =>
            {
                for (int i = 0; i < 6; i++)
                {
                    Thread.Sleep(5000);
                    Console.WriteLine("5");
                }
            });
            Thread t2 = new Thread(() =>
            {
                for (int i = 0; i < 3; i++)
                {
                    Thread.Sleep(1111);
                    Console.WriteLine("1");
                }
            });
            t1.Start();
            t2.Start();
        }
        /// <summary>
        /// Resenje Zadatka 2
        /// Linq
        /// </summary>
        public static void Assignment2()
        {
            int[] numbers = { 1, 2, 5, 3, 2, 3 };

            var numbersList = (from n in numbers
                                where n < 3
                                select (double)n).ToList();
            
            numbersList.Add(0.5);

            numbersList.ForEach(d=>Console.WriteLine(d));
        }
        /// <summary>
        /// Resenje Zadatak 3
        /// Reflection
        /// </summary>
        public static void Assignment3()
        {
            Student s = new Student { Ime = "Pera", Prezime = "Peric", BrIndeksa = "111/11" };
            
            Console.WriteLine(s.Ime);

            s.PopuniSvojstvo("Ime", "Mile");

            Console.WriteLine(s.Ime);
        }

    }
    /// <summary>
    /// Klasa student iz Zadatak3 a)
    /// </summary>
    class Student
    {
        public string Ime { get; set; }
        //Moze i ovako
        /*
            private string ime;

            public string Ime
            {
                get { return ime; }
                set { ime = value; }
            }
         */
        public string Prezime { get; set; }

        public string BrIndeksa { get; set; }


        /// <summary>
        /// Metoda resenje Zadatak 3 c) 
        /// </summary>
        /// <param name="svojstvo">Property koji treba na osnovu imena da se popuni</param>
        /// <param name="vrednost">value za taj Property</param>
        public void PopuniSvojstvo(string svojstvo, string vrednost)
        {
            Type type = this.GetType();
            
            PropertyInfo prop = type.GetProperty(svojstvo);
            
            if (prop!=null)
            {
                prop.SetValue(this, vrednost);
            }

        }


    }
}
